package com.ny.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailService {
    @Autowired
    private JavaMailSender mailSender;
    // 获取到配置文件的邮箱号
    @Value("${spring.mail.username}")
    private String fromEmail;
    public  void sendEmail(String toEmail,String code){

        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromEmail);// 发件人的QQ邮箱号
        message.setTo(toEmail);// 收件人的QQ邮箱号
        message.setSubject(" 重置密码验证码");// 主题
        message.setText("验证码为："+code);// 内容
        mailSender.send(message);// 发送邮件

    }
    // 随机生成验证码
    public String getCode(){
        int code = (int)((Math.random()*9000)+1000);
        return  String.valueOf(code);
    }
}
